<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2024/2/23 13:57
 */


declare(strict_types=1);

use Hyperf\Context\ApplicationContext;
use Hyperf\AsyncQueue\JobInterface;
use Hyperf\AsyncQueue\Driver\DriverFactory;
use Qbhy\HyperfAuth\AuthManager;
use function Hyperf\Support\env;
use function Hyperf\Support\make;
use function Hyperf\Config\config;
if(!function_exists('di'))
{
    function di($id = null)
    {
        $container = ApplicationContext::getContainer();

        if($id)
        {
            return $container->get($id);
        }
        return $container;
    }
}


/**
 * 获取用户登录后的授权
 */
if(!function_exists('auth'))
{
    function auth(string $guard = 'sso')
    {
        if (is_null($guard)) $guard = config('auth.default.guard');

        return make(AuthManager::class)->guard($guard);
    }
}

if(!function_exists('queue_push'))
{
    function queue_push(JobInterface $job, string $key = 'default', int $delay = 0):bool
    {
        $driver = di()->get(DriverFactory::class)->get($key);
        return $driver->push($job,$delay);
    }
}
